package TUILayer;

import ModelLayer.*;
import java.util.Random;
import java.util.ArrayList;

public class dataLoader
{
    private SalesLine product;
    private Item item;
    private Customer customer;
    private DeliveryType deliveryType;
    private PaymentType paymentType;
    private Staff staff;
    private Discount discount;
    
    private Discounts discounts;
    private Customers customers;
    private DeliveryTypes deliveryTypes;
    private PaymentTypes paymentTypes;
    private Items items;
    private Products products;
    private Staffs staffs;
    
    public dataLoader()
    {
        product = new SalesLine();
        item = new Item();
        customer = new Customer();
        deliveryType = new DeliveryType();
        paymentType = new PaymentType();
        staff = new Staff();
        discount = new Discount();
        
        discounts.getInstance();
        customers.getInstance();
        deliveryTypes.getInstance();
        paymentTypes.getInstance();
        items.getInstance();
        staffs.getInstance();
        products.getInstance();
    }
    
    public void loadData()
    {
        for(int i=0;i<10;i++)
        {
            generateDiscount();
            discounts.addDiscount(discount);
            
            generateDeliveryType();
            deliveryTypes.addDeliveryType(deliveryType);
            
            generatePaymentType();
            paymentTypes.addPaymentType(paymentType);
            
            generateCustomers();
            customers.addCustomer(customer);
            
            generateItems();
            items.addItem(item);
            
            generateProducts();
            products.addProduct(product);
            
            generateStaff();
            staffs.addStaff(staff);
        }
    }

    private void generateProducts()
    {
        product.setName(generateRandomString());
        product.setId(generateRandomString());
        product.setBarCode(generateRandomString());
        product.setDateAdded(generateRandomString());
        product.setLocation(generateRandomString());
        product.setDiscount(discount);
    }
    
    private void generateItems()
    {
        item.setId(generateRandomString());
        item.setName(generateRandomString());
        item.setPrice(generateRandomDouble());
        item.setDiscount(discount);
        item.setSalesLine(product);
    }
    
    private void generateCustomers()
    {
        customer.setId(generateRandomString());
        customer.setName(generateRandomString());
        customer.setSurname(generateRandomString());
        customer.setAddress(generateRandomString());
        customer.setPhone(generateRandomString());
        customer.setCpr(generateRandomString());
        customer.setType(generateRandomString());
        customer.setDiscount(discount);
    }
    
    private void generateDiscount()
    {
        discount.setId(generateRandomString());
        discount.setName(generateRandomString());
        discount.setPercentage(generateRandomInteger());
    }
    
    private void generateStaff()
    {
        staff.setId(generateRandomString());
        staff.setName(generateRandomString());
        staff.setSurname(generateRandomString());
        staff.setAddress(generateRandomString());
        staff.setPhone(generateRandomString());
        staff.setCpr(generateRandomString());
        staff.setSalary(generateRandomDouble());
        staff.setRoles(generateRandomString());
    }
    
    private void generateDeliveryType()
    {
        deliveryType.setId(generateRandomString());
        deliveryType.setName(generateRandomString());
        deliveryType.setPricePerKm(generateRandomDouble());
    }
    
    private void generatePaymentType()
    {
        paymentType.setId(generateRandomString());
        paymentType.setName(generateRandomString());
        paymentType.setType(generateRandomString());
    }
    
    private String generateRandomString()
    {
        Random rnd = new Random();
        double d = rnd.nextDouble();
        return String.valueOf(d);
    }
    
    private int generateRandomInteger()
    {
        Random rnd = new Random();
        return rnd.nextInt();
    }
    
    private double generateRandomDouble()
    {
        Random rnd = new Random();
        return rnd.nextDouble();
    }
}
